package com.cqndt.disaster.device.controller;

import java.util.Map;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import com.cqndt.disaster.device.util.Result;
import javax.servlet.http.HttpServletRequest;
import com.cqndt.disaster.device.vo.TabVideoMonitoringVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.redis.core.StringRedisTemplate;
import com.cqndt.disaster.device.service.TabVideoMonitoringService;

/**
 * @author lgb
 * @date 2020-9-1
 * @return 视频监控
 **/
@RestController
@RequestMapping(value="/api/v2/videoMonitor")
public class TabVideoMonitorController extends BaseController{

    @Autowired
    private TabVideoMonitoringService tabVideoMonitoringService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * @param request
     * @param page 页数
     * @param limit 条数
     * @param deviceName 设备名称
     * @return 设备列表
     **/
    @PostMapping(value="getVideoMonitorMsgByAreacode")
    public Result getVideoMonitorMsgByAreacode(HttpServletRequest request, Integer page, Integer limit, String deviceName){
        String userId = request.getHeader("id");
        String areaCode= redisTemplate.opsForValue().get("areaCode"+userId);
        String unitLevel=redisTemplate.opsForValue().get("level"+userId);
        TabVideoMonitoringVo vo = new TabVideoMonitoringVo();
        vo.setUserId(Integer.parseInt(userId));
        vo.setDeviceName(deviceName);
        vo.setAreaCode(areaCode);
        vo.setAreaCodeSplit(areaCode.substring(0,2));
        vo.setLevel(unitLevel);
        PageHelper.startPage(page,limit);
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<Map<String,Object>>(tabVideoMonitoringService.getVideoMonitorMsgByAreacode(vo));
        Result result = new Result();
        result.setCount((int)pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }
}